﻿using System;
using System.Windows.Forms;
using Galaxy.AutoCAD.Options;
using System.Collections.Generic;
using AutoCADApp = Autodesk.AutoCAD.ApplicationServices;

namespace Galaxy.AutoCAD.Windows
{
    public partial class LaminateDirectionWindow : Form
    {
        public LaminateDirectionWindow()
        {
            InitializeComponent();
        }
        
        private void LaminateDirectionWindow_Load(object sender, EventArgs e)
        {
            comboBox1.Focus();
            foreach (string outString in LaminateOptionTool.LaminateDirectionBlockNameSet)
            {
                comboBox1.Items.Add(outString);
            }
            if (comboBox1.Items.Count > 0)
            {
                if (comboBox1.Items.Contains("Galaxy-叠合板-方向-吊装"))
                {
                    comboBox1.SelectedItem = "Galaxy-叠合板-方向-吊装";
                }
                else
                {
                    comboBox1.SelectedItem = comboBox1.Items[0];
                }
            }
            textBox1.Text = "0";
            textBox2.Text = "0";
        }

        private void comboBox1_Click(object sender, EventArgs e)
        {
            comboBox1.SelectAll();
        }

        private void textBox1_Click(object sender, EventArgs e)
        {
            textBox1.SelectAll();
        }

        private void textBox2_Click(object sender, EventArgs e)
        {
            textBox2.SelectAll();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            LaminateOptionTool.LaminateDirectionPass = "1";
            if (comboBox1.SelectedItem == null)
            {
                AutoCADApp.Application.ShowAlertDialog("请选择有效值!");
                comboBox1.Focus();
                return;
            }
            else
            {
                LaminateOptionTool.LaminateDirectionBlockName = comboBox1.Text;
            }
            double laminateDirectionXDeviantValue;
            if (double.TryParse(textBox1.Text, out laminateDirectionXDeviantValue))
            {
                LaminateOptionTool.LaminateDirectionXDeviantValue = laminateDirectionXDeviantValue;
            }
            else
            {
                AutoCADApp.Application.ShowAlertDialog("请输入有效值!");
                textBox1.Focus();
                return;
            }
            double laminateDirectionYDeviantValue;
            if (double.TryParse(textBox2.Text, out laminateDirectionYDeviantValue))
            {
                LaminateOptionTool.LaminateDirectionYDeviantValue = laminateDirectionYDeviantValue;
            }
            else
            {
                AutoCADApp.Application.ShowAlertDialog("请输入有效值!");
                textBox2.Focus();
                return;
            }
            this.Close();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            LaminateOptionTool.LaminateDirectionPass = "0";
            LaminateOptionTool.LaminateDirectionBlockNameSet = new List<string>();
            LaminateOptionTool.LaminateDirectionBlockName = null;
            LaminateOptionTool.LaminateDirectionXDeviantValue = 0.0;
            LaminateOptionTool.LaminateDirectionYDeviantValue = 0.0;
            this.Close();
        }
    }
}
